<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="130px">
      <el-form-item label="UserID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入userID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="CustNo" prop="custNo">
        <el-input
          v-model="queryParams.custNo"
          placeholder="请输入CustNo"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="First Name" prop="firstName">
        <el-input
          v-model="queryParams.firstName"
          placeholder="请输入First Name"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Middle Name" prop="middleName">
        <el-input
          v-model="queryParams.middleName"
          placeholder="请输入Middle Name"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Last Name" prop="lastName">
        <el-input
          v-model="queryParams.lastName"
          placeholder="请输入Last Name"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Date of Birth" prop="birthDate">
        <el-input
          v-model="queryParams.birthDate"
          placeholder="请输入Date of Birth"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Age" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入Age"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Gender" prop="gender">
        <el-select v-model="queryParams.gender" placeholder="请选择Gender" clearable size="small">
          <el-option
            v-for="dict in genderOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="BVN" prop="bvnAccount">
        <el-input
          v-model="queryParams.bvnAccount"
          placeholder="请输入BVN"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="BVN绑定手机号" prop="phoneNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.phoneNumber"-->
<!--          placeholder="请输入BVN绑定手机号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="AccountNumber" prop="AccountNumber">
        <el-input
          v-model="queryParams.AccountNumber"
          placeholder="请输入AccountNumber"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="State" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bizsys:real_name_auth:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bizsys:real_name_auth:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bizsys:real_name_auth:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bizsys:real_name_auth:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="real_name_authList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="ID" align="center" width="100" prop="id"/>
      <el-table-column label="UserID" align="center" width="300" prop="userId"/>
      <el-table-column label="CustNo" align="center" width="200" prop="custNo"/>
      <el-table-column label="Firstname" align="center" width="180" prop="firstName"/>
      <el-table-column label="Middlename" align="center" width="180" prop="middleName"/>
      <el-table-column label="Lastname" align="center" width="180" prop="lastName"/>
      <el-table-column label="DateOfBirth" align="center" width="180" prop="birthDate"/>
      <el-table-column label="Age" align="center" prop="age"/>
      <el-table-column label="Gender" align="center" prop="gender" :formatter="genderFormat"/>
      <el-table-column label="BVN" align="center" width="180" prop="bvnAccount"/>
<!--      <el-table-column label="BVN绑定手机号" align="center" prop="phoneNumber"/>-->
      <el-table-column label="AccountNumber" align="center" width="180" prop="accountNumber"/>
      <el-table-column label="State" align="center" prop="state" :formatter="stateFormat"/>
      <el-table-column label="Remark" align="center" prop="remark"/>
      <el-table-column label="Operation" align="center" width="140" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bizsys:real_name_auth:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bizsys:real_name_auth:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改实名认证对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID"/>
        </el-form-item>
        <el-form-item label="客户号" prop="custNo">
          <el-input v-model="form.custNo" placeholder="请输入客户号"/>
        </el-form-item>
        <el-form-item label="First Name" prop="firstName">
          <el-input v-model="form.firstName" placeholder="请输入First Name"/>
        </el-form-item>
        <el-form-item label="Middle Name" prop="middleName">
          <el-input v-model="form.middleName" placeholder="请输入Middle Name"/>
        </el-form-item>
        <el-form-item label="Last Name" prop="lastName">
          <el-input v-model="form.lastName" placeholder="请输入Last Name"/>
        </el-form-item>
        <el-form-item label="Date of Birth" prop="birthDate">
          <el-input v-model="form.birthDate" placeholder="请输入Date of Birth"/>
        </el-form-item>
        <el-form-item label="Age" prop="age">
          <el-input v-model="form.age" placeholder="请输入Age"/>
        </el-form-item>
        <el-form-item label="Gender" prop="gender">
          <el-select v-model="form.gender" placeholder="请选择Gender">
            <el-option
              v-for="dict in genderOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="BVN_Account" prop="bvnAccount">
          <el-input v-model="form.bvnAccount" placeholder="请输入BVN_Account"/>
        </el-form-item>
        <el-form-item label="BVN绑定手机号" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入BVN绑定手机号"/>
        </el-form-item>
        <el-form-item label="Account_number" prop="AccountNumber">
          <el-input v-model="form.AccountNumber" placeholder="请输入Account_number"/>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入状态"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listReal_name_auth,
  getReal_name_auth,
  delReal_name_auth,
  addReal_name_auth,
  updateReal_name_auth,
  exportReal_name_auth
} from "@/api/bizsys/real_name_auth";

export default {
  name: "Real_name_auth",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 实名认证表格数据
      real_name_authList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // Gender字典
      genderOptions: [],
      // 状态字典
      stateOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        custNo: null,
        firstName: null,
        middleName: null,
        lastName: null,
        birthDate: null,
        age: null,
        gender: null,
        bvnAccount: null,
        phoneNumber: null,
        AccountNumber: null,
        state: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          {required: true, message: "用户ID不能为空", trigger: "blur"}
        ],
        custNo: [
          {required: true, message: "客户号不能为空", trigger: "blur"}
        ],
        firstName: [
          {required: true, message: "First Name不能为空", trigger: "blur"}
        ],
        middleName: [
          {required: true, message: "Middle Name不能为空", trigger: "blur"}
        ],
        lastName: [
          {required: true, message: "Last Name不能为空", trigger: "blur"}
        ],
        birthDate: [
          {required: true, message: "Date of Birth不能为空", trigger: "blur"}
        ],
        gender: [
          {required: true, message: "Gender不能为空", trigger: "change"}
        ],
        bvnAccount: [
          {required: true, message: "BVN_Account不能为空", trigger: "blur"}
        ],
        phoneNumber: [
          {required: true, message: "BVN绑定手机号不能为空", trigger: "blur"}
        ],
        AccountNumber: [
          {required: true, message: "Account_number不能为空", trigger: "blur"}
        ],
        createTime: [
          {required: true, message: "创建时间不能为空", trigger: "blur"}
        ],
        updateTime: [
          {required: true, message: "更新时间不能为空", trigger: "blur"}
        ]
      }
    };
  },
  created() {
    // this.getList();
    this.getDicts("biz_gender").then(response => {
      this.genderOptions = response.data;
    });
    this.getDicts("state").then(response => {
      this.stateOptions = response.data;
    });
  },
  methods: {
    /** 查询实名认证列表 */
    getList() {
      this.loading = true;
      listReal_name_auth(this.queryParams).then(response => {
        this.real_name_authList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // Gender字典翻译
    genderFormat(row, column) {
      return this.selectDictLabel(this.genderOptions, row.gender);
    },
    // 状态字典翻译
    stateFormat(row, column) {
      return this.selectDictLabel(this.stateOptions, row.state);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        custNo: null,
        firstName: null,
        middleName: null,
        lastName: null,
        birthDate: null,
        age: null,
        gender: null,
        bvnAccount: null,
        phoneNumber: null,
        AccountNumber: null,
        state: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加实名认证";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getReal_name_auth(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改实名认证";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateReal_name_auth(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReal_name_auth(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除实名认证编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delReal_name_auth(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有实名认证数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportReal_name_auth(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
